package com.xiaohuihui.springbootsecurity.domain;

import lombok.Data;

import java.io.Serializable;

/**
 * <p>
 * 统一接口返回值
 * </p>
 *
 * @since 2019/5/22
 */
@Data
public class ApiResult<T> implements Serializable {

    /**
     * 返回码
     */
    private long code;

    /**
     * 描述
     */
    private String msg;

    /**
     * 数据
     */
    private T data;

    public ApiResult() {

    }

    public static <T> ApiResult<T> ok() {
       return ok(null);
    }

    public static <T> ApiResult<T> ok(T data) {
        return restResult(data, 200,"success");
    }

    public static <T> ApiResult<T> failed(String msg) {
        return restResult(null, 9999, msg);
    }

    private static <T> ApiResult<T> restResult(T data, long code, String msg) {
        ApiResult<T> apiResult = new ApiResult<>();
        apiResult.setCode(code);
        apiResult.setData(data);
        apiResult.setMsg(msg);
        return apiResult;
    }



}
